package com.ytktt.study.week12.task7.mapper;

import com.ytktt.study.week12.task7.entity.OrderEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * TODO
 *
 * @author ytk
 */
@Mapper
public interface OrderMapper {

    @Insert("INSERT INTO tb_order(id, status, task_region) VALUES (#{id,jdbcType=BIGINT}, #{status,jdbcType=TINYINT}, #{taskRegion,jdbcType=INTEGER})")
    int insertOrder(OrderEntity entity);

    @Update("UPDATE tb_order SET status = #{status,jdbcType=TINYINT} WHERE id = #{id,jdbcType=BIGINT}")
    int updateOrderStatus(OrderEntity entity);

    @Select("<script>SELECT id, status, task_region AS taskRegion FROM tb_order <where> task_region = #{region} AND status = #{status} <if test='successMaxId != null'> AND id > #{successMaxId}</if></where></script>")
    List<OrderEntity> selectByTaskRegionAndStatus(@Param("region") int region, @Param("status") byte status, @Param("successMaxId") Long successMaxId);
}
